#ifndef __PREF_H__
#define __PREF_H__

#include <string>
#include "table.hpp"

using namespace std;


//--------------------------------------------------------
class PrefVal
{
private:
  enum Source
    {
      SRC_NULL = 0,
      CMD_LINE = 1,
      CONF_FILE = 2,
    } src;
  string val; 
  
public:
  PrefVal () : src (SRC_NULL) {}
  void setVal (string &_val, Source &_src)
  {
    val = _val;
    src = _src;
  }
  void setVal (string &_val)
  {
    val = _val;
  }
  string getVal () { return val; }

};


//--------------------------------------------------------
class PrefDef
{
public:
  enum Type
    {
      PT_NULL = 0,
      PT_STR,
      PT_INT,
      PT_BOOL,
    };

  PrefDef () : idx (0), stackable (false), type (PT_NULL) {}
  ~PrefDef () {}
  void define (string &_cliName, string &_confName, bool &_stackable, 
	       Type &_type, string &_defaultVal, string &_description);

  string getValue (unsigned int &idx);
  bool setValue (string &value);

  string getCliName () { return this->cliName; }
  bool isWithVal () { return this->stackable; }
  Type getType () { return this->type; }
  string getDefault () { return this->defaultVal; }
  string getDesc () { return this->description; }
  unsigned int getCount () { return this->idx; }

private:
  int idx;
  string cliName; 
  string confName; 
  bool stackable; 
  Type type; 
  string defaultVal; 
  string description;
  PTree <PrefVal> valList;
};


//--------------------------------------------------------
class Preference
{
public:

  Preference () {};
  ~Preference () {};

  bool define (string cliName, string confName, bool stackable, PrefDef::Type type, 
	       string defaultVal, string description);

  bool import (int c, char *v[]);
  int lookup (string name);
  string getStr (string name, unsigned int idx);
  int getInt (string name, unsigned int idx);
  bool getBool (string name, unsigned int idx);

  string getError () { return this->errmsg; }

private:
  PTree<PrefDef> defList;  
  string errmsg;
};


#endif // __PREF_H__
